<template>
<div>
  <textarea id="kindeditor" ref="editor" ></textarea>
</div>
</template>

<script>
import { SERVER_BASE_URL, STATIS_HOST } from "../../api/config.js";
export default {
  name: "KindEditor",
  data() {
    return {
      ke: null
    };
  },
  props: {
    config: Object
  },
  params() {
    return {
      token: localStorage.getItem("token")
    };
  },
  methods: {
    getContent() {
      return this.ke ? this.ke.html() : "";
    },
    setContent(html) {
      if (this.ke) {
        this.ke.html(html);
      }
    },
    isEmpty() {
      return this.ke ? this.ke.isEmpty() : true;
    }
  },
  mounted() {
    let _this = this;
    if (KindEditor ) {
      let configuration = {
        themesPath: "../../../static/plugins/kindeditor/themes/",
        themeType: "simple",
        langPath: "../../../static/plugins/plugins/kindeditor/lang/",
        langType: "zh-CN",
        pluginsPath: "../../../static/plugins/kindeditor/plugins/"
      };
       if (_this.config) {
        for (let k in _this.config) {
          configuration[k] = _this.config[k];
        }
      }
      configuration["staticHost"] = STATIS_HOST
      configuration["extraFileUploadParams"] = {
        token: localStorage.getItem("token")
      };
      _this.ke = KindEditor.create("#" + _this.$refs["editor"].id, configuration);
    }
    
  },
  destroyed() {
    if (this.ke) {
      this.ke.remove();
      this.ke = null;
    }
  }
};
</script>

<style>
.ke-icon-uploadimg {
  background-image: url(../../../static/plugins/kindeditor/themes/default/default.png);
  background-position: 0px -496px;
  width: 16px;
  height: 16px;
}

.ke-icon-uploadfile {
  background-image: url(../../../static/plugins/kindeditor/themes/default/default.png);
  background-position: 0px -1040px;
  width: 16px;
  height: 16px;
}
</style>
